﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mimoza.Common;
using Mimoza.Transport;

namespace Mimoza.DBLayer.Transport
{
    public class PoliciesRepositoryCustomRequest
    {
        public enum CustomOperationType
        {
            None,
            GetPolicy,
            GetPolicies
        }

        public PoliciesRepositoryCustomRequest()
        {
        }

        public PoliciesRepositoryCustomRequest(CustomOperationType operationType)
        {
            Init(operationType, null);
        }

        public PoliciesRepositoryCustomRequest(CustomOperationType operationType,
            string argument1)
        {
            Init(operationType, argument1);
        }

        void Init(CustomOperationType operationType, string argument1)
        {
            OperationType = operationType;
            Argument1 = argument1;
        }

        public CustomOperationType OperationType = CustomOperationType.None;
        public string Argument1 = null;
    }

    public class PoliciesRepositoryTranferRequest :
        TransferObjectGeneric<PoliciesRepositoryTranferRequest, RepositoryReply<PolicyRecord>>
    {
        public PoliciesRepositoryTranferRequest()
        {
        }

        public PoliciesRepositoryTranferRequest(Operation oper, PolicyRecord record)
        {
            Request.Operation = oper;
            Request.Object = record;
        }

        public PoliciesRepositoryTranferRequest(PoliciesRepositoryCustomRequest customReq)
        {
            Request.Operation = Operation.Custom;
            Request.CustomRequest = customReq;
        }

        override public RepositoryReply<PolicyRecord> ProcessRequest()
        {
            return Request.Process(Connection, Repository) as RepositoryReply<PolicyRecord>;
        }

        public RepositoryRequest<
            PolicyRecord,
            ServerRepository<PolicyRecord, PoliciesRepositoryCustomRequest, IDBPolicyRepository>,
            PoliciesRepositoryCustomRequest,
            IDBPolicyRepository> Request = new RepositoryRequest<
                PolicyRecord,
                ServerRepository<PolicyRecord, PoliciesRepositoryCustomRequest, IDBPolicyRepository>,
                PoliciesRepositoryCustomRequest,
                IDBPolicyRepository>();

        public static ServerRepository<PolicyRecord, PoliciesRepositoryCustomRequest, IDBPolicyRepository> Repository = null;
    }
}
